const path = require('path');
const nodeExternals = require('webpack-node-externals');

const env = process.env.NODE_ENV;

module.exports = {
    target: 'node',
    mode: env,
    entry: path.resolve(__dirname, '../serverRender/serverRender.js'),
    output: {
        filename: 'bundle.js',
        path: path.resolve(__dirname, '../build')
    },
    externals: [nodeExternals()],
    resolve: {
        extensions: [".tsx", ".ts", ".js", ".jsx"],
    },
    module: {
        rules: [{
            test: /\.(j|t)s(x)?$/,
            loader: 'babel-loader',
            exclude: /node_modules/
        },{
            test: /\.(c|le)ss$/,
            use: [
                'isomorphic-style-loader',
                'css-loader',
                'postcss-loader',{
                    loader: "less-loader",
                    options: {
                        lessOptions: {
                            javascriptEnabled: true,
                        },
                    },
                }
            ]
        },{
            test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
            use: {
                loader: "url-loader",
                options: {
                    limit: 1024 * 10,
                    name: "img/[name].[hash:7].[ext]",
                },
            },
        },
        {
            test: /\.(ttf|eot|otf|woff2?)(\?.*)?$/,
            loader: "file-loader",
            options: {
                name: "fonts/[name].[hash:7].[ext]",
            },
        }]
    }
};
